/**
 * @file   SplatCodeFactory.java
 * @date   2012-11-7上午9:35:01
 * @author User
 */
package com.gzceb.zhgjj.mina;

import java.nio.charset.Charset;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.ProtocolCodecFactory;
import org.apache.mina.filter.codec.ProtocolDecoder;
import org.apache.mina.filter.codec.ProtocolEncoder;
import org.apache.mina.filter.codec.textline.LineDelimiter;
import org.apache.mina.filter.codec.textline.TextLineDecoder;
import org.apache.mina.filter.codec.textline.TextLineEncoder;

/**
 * <p>编码协议转换类。</p>
 *
 * @date   2012-11-7上午9:35:01 
 * @author liqing
 * @description 
 */
public class SplatCodeFactory implements ProtocolCodecFactory {

	private final TextLineEncoder encoder;
    private final TextLineDecoder decoder;
    
    public SplatCodeFactory() {
        this(Charset.forName("GBK"));
    }
    
    public SplatCodeFactory(Charset charset) {
        encoder = new TextLineEncoder(charset, LineDelimiter.UNIX);   
        decoder = new TextLineDecoder(charset, LineDelimiter.AUTO);   
        }


	
	/* (non-Javadoc)
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getEncoder(org.apache.mina.core.session.IoSession)
	 */
	@Override
	public ProtocolEncoder getEncoder(IoSession session) throws Exception {
		// TODO Auto-generated method stub
		//System.out.println("编码协议转换encoder：");
		return encoder;
	}

	/* (non-Javadoc)
	 * @see org.apache.mina.filter.codec.ProtocolCodecFactory#getDecoder(org.apache.mina.core.session.IoSession)
	 */
	@Override
	public ProtocolDecoder getDecoder(IoSession session) throws Exception {
		// TODO Auto-generated method stub
		//System.out.println("编码协议转换decodedr：");
		return decoder;
	}
	
	public int getEncoderMaxLineLength() {
        return encoder.getMaxLineLength();
    }
    public void setEncoderMaxLineLength(int maxLineLength) {
        encoder.setMaxLineLength(maxLineLength);
    }
    public int getDecoderMaxLineLength() {
        return decoder.getMaxLineLength();
    }
    public void setDecoderMaxLineLength(int maxLineLength) {
        decoder.setMaxLineLength(maxLineLength);
    }

}
